<?php
/**
 * @file
 * @package mileage
 * @version $Id$
**/

if (!defined('XOOPS_ROOT_PATH')) {
	exit;
}

require_once MILEAGE_TRUST_PATH . '/class/AbstractFilterForm.class.php';

define('MILEAGE_REC_SORT_KEY_REC_ID',       1);
define('MILEAGE_REC_SORT_KEY_POINT',        2);
define('MILEAGE_REC_SORT_KEY_MILE_ID',      3);
define('MILEAGE_REC_SORT_KEY_UID',          4);
define('MILEAGE_REC_SORT_KEY_REG_UNIXTIME', 5);

define('MILEAGE_REC_SORT_KEY_DEFAULT', MILEAGE_REC_SORT_KEY_REG_UNIXTIME);//REG_UNIXTIME

/**
 * Mileage_Admin_MileFilterForm
**/
class Mileage_RecFilterForm extends Mileage_AbstractFilterForm
{
	/**
	 * @var  string[]
	 * 
	 * @public
	**/
	var $mSortKeys = array(
		MILEAGE_REC_SORT_KEY_REC_ID       => 'rec_id',
		MILEAGE_REC_SORT_KEY_POINT        => 'point',
		MILEAGE_REC_SORT_KEY_MILE_ID      => 'mile_id',
		MILEAGE_REC_SORT_KEY_UID          => 'uid',
		MILEAGE_REC_SORT_KEY_REG_UNIXTIME => 'reg_unixtime',
	);

	/**
	 * getDefaultSortKey
	 * 
	 * @param   void
	 * 
	 * @return  void
	**/
	public function getDefaultSortKey()
	{
		return MILEAGE_REC_SORT_KEY_DEFAULT * -1;
	}

	/**
	 * fetch
	 * 
	 * @param   void
	 * 
	 * @return  void
	**/
	public function fetch()
	{
		parent::fetch();

		$root =& XCube_Root::getSingleton();

		if (($value = $root->mContext->mRequest->getRequest('rec_id')) !== null) {
			$this->mNavi->addExtra('rec_id', $value);
			$this->_mCriteria->add(new Criteria('rec_id', $value));
		}

		if (($value = $root->mContext->mRequest->getRequest('point')) !== null) {
			$this->mNavi->addExtra('point', $value);
			$this->_mCriteria->add(new Criteria('point', $value));
		}

		if (($value = $root->mContext->mRequest->getRequest('mile_id')) !== null) {
			$this->mNavi->addExtra('mile_id', $value);
			$this->_mCriteria->add(new Criteria('mile_id', $value));
		}

		if ($root->mContext->mXoopsUser->isAdmin() && ($value = $root->mContext->mRequest->getRequest('uid')) !== null) {
			$uid = $value;
			$this->mNavi->addExtra('uid', $uid);
		} else {
			$uid = $root->mContext->mXoopsUser->get('uid');
		}
		$this->_mCriteria->add(new Criteria('uid', $uid));

		if (($value = $root->mContext->mRequest->getRequest('reg_unixtime')) !== null) {
			$this->mNavi->addExtra('reg_unixtime', $value);
			$this->_mCriteria->add(new Criteria('reg_unixtime', $value));
		}

		$this->_mCriteria->addSort($this->getSort(), $this->getOrder());
	}
}

